#include <iostream>
#include <string>
#include <functional>

//线程封装
typedef void*((*fun_t)(void*));
struct ThreadData
{
    std::string _name;
    void* _args;
};

class thread
{
public:
    thread(int num,fun_t callback,void* args) 
    :_func(callback)
    {
        char buffname[64];
        snprintf(buffname, sizeof buffname, "Thread-%d", num);
        _name = buffname;

        _tdata._name = _name;
        _tdata._args = args;
    }
    void start()
    {
        pthread_create(&_tid,nullptr,_func,(void*)&_tdata);
    }
    void join()
    {
        pthread_join(_tid,nullptr);
    }
    std::string name()
    {
        return _name;
    }
    ~thread()
    {
        ;
    }
private:
    std::string _name;
    fun_t _func;
    ThreadData _tdata;
    pthread_t _tid;
};